package com.inss.trial.service;

import com.inss.trial.utils.CommUtils;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpService {
    public void init() throws IOException {
        ServerSocket server = new ServerSocket(1688);
        Socket accept = server.accept();
        String resStr = "<root><resultcode>0000</resultcode></root>";
        int headLen = 14;
        byte[] content = resStr.getBytes();
        String packHead = CommUtils.fillLenToStr(true, String.valueOf(content.length), "0", headLen);
        System.out.println("发送报文头：" + packHead);
        System.out.println("发送报文体:" + resStr);
        OutputStream out = accept.getOutputStream();
        out.write(packHead.getBytes());
        out.write(content);
        out.flush();
        out.close();
    }
}
